/**
 * 
 */
package com.geezdata.cps.ttk.domain.factory;

import java.util.Date;

import com.geezdata.cps.base.utils.BeanUtil;
import com.geezdata.cps.ttk.common.request.CreateOrUpdatePromotionSpaceRequest;
import com.geezdata.cps.ttk.common.vo.PromotionSpaceReqVO;
import com.geezdata.cps.ttk.domain.domain.PromotionSpace;

/**
 * @author tfwan
 * @date 创建时间：2018年6月12日 下午4:03:18
 *
 */
public class PromotionSpaceFactory {

	public static PromotionSpace newInstance(CreateOrUpdatePromotionSpaceRequest request , PromotionSpace exsitsPromotionSpace) {
		PromotionSpaceReqVO promotionSpaceReqVO = request.getPromotionSpaceReqVO();
		PromotionSpace promotionSpace = BeanUtil.convert(promotionSpaceReqVO, PromotionSpace.class);
    
    	Date now = new Date();
    	String currentUser = request.getCurrentUser();
    	
    	if (exsitsPromotionSpace == null) {
    		promotionSpace.setCreatedUser(currentUser);
    		promotionSpace.setCreatedAt(now);
    		promotionSpace.setStatus(1);
    	} else {
    		promotionSpace.setPromotionSpaceId(exsitsPromotionSpace.getPromotionSpaceId());
    	}
    	promotionSpace.setUpdatedUser(currentUser);
    	promotionSpace.setUpdatedAt(now);
    	
        return promotionSpace;
	}
}
